<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="24" :xs="24">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
          <el-form-item label="所属分组" prop="cateNamespaceLike">
            <el-select
              v-model="queryParams.cateNamespaceLike" @change="handleSelectCateGroup" placeholder="请选择所属分组" clearable
              style="width: 240px;">
              <el-option
                v-for="dict in cateGroupCodeOptions" :key="dict.dictValue" :label="dict.dictLabel"
                :value="dict.dictValue" />
            </el-select>
          </el-form-item>
          <el-form-item label="参数名称" prop="entityNameLike">
            <el-input
              v-model="queryParams.entityNameLike" placeholder="请输入参数名称" clearable
              style="width: 240px"
              @keyup.enter="handleQuery" />
          </el-form-item>
          <el-form-item label="属性描述" prop="entityDescLike">
            <el-input
              v-model="queryParams.entityDescLike" placeholder="请输入属性描述" clearable
              style="width: 240px"
              @keyup.enter="handleQuery" />
          </el-form-item>
          <el-form-item>
            <search-button @click="handleQuery" :perm="['rule:entity:info:search']" />
            <reset-button @click="resetQuery" :perm="['rule:entity:info:search']" />
          </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
          <add-button
            @click="handleAddModel" :perm="['rule:entity:info:insert']" :roleType="['app']"
            text="新增模型实体" />
          <add-button
            @click="handleBatchAddModel" :perm="['rule:entity:info:insert']" :roleType="['app']"
            text="批量新增模型实体" />
          <delete-button :disabled="deleteBtnDisabled" @click="handleDeleteModelByIds" :perm="['rule:entity:info:insert']" :roleType="['app']" text="批量删除" />
          <import-button @click="handleImport" :perm="['uni:entity:info:import']" :roleType="['conf']" text="迁入"></import-button>
          <right-toolbar :showSearch="showSearch" @query-table="getList" :perm="['rule:entity:info:search']" />
        </el-row>
        <el-table
          v-loading="loading" :data="dataList"
          style="width: 100%;margin-bottom: 20px;"
          row-key="entityId"
          ref="table"
          @select="handleSelectionChange"
          >
          <el-table-column type="selection" width="80" />
          <el-table-column label="参数名称" prop="entityName" :show-overflow-tooltip="true" min-width="120" />
          <el-table-column
            label="参数描述" align="left" prop="entityDesc" :show-overflow-tooltip="true"
            min-width="120" />
          <el-table-column label="所属分组" align="left" prop="cateNamespace" :show-overflow-tooltip="true" min-width="120">
            <template #default="scope">
              {{ selectDictLabel(cateGroupCodeOptions, scope.row.cateNamespace) }}
            </template>
          </el-table-column>
          <el-table-column label="参数类型" prop="entityClass" align="center" width="110">
            <template #entityClass="scope">{{ selectDictLabel(entityClassOptions, scope.row.entityClass) }}</template>
          </el-table-column>
          <el-table-column
            label="修改时间" align="center" prop="updateTime" :show-overflow-tooltip="true"
            width="160" />
          <el-table-column
            label="操作" align="center" width="400" class-name="small-padding fixed-width" fixed="right"
            v-if="hasRoleType(['app'])">
            <template #default="scope">
              <text-download-button @click="handleExport(scope.row)" v-if="scope.row.parentId === '0'" text="迁出"/>
              <text-delete-button
                @click="handleDelete(scope.row)" :perm="['rule:entity:info:delete']"
                :roleType="['app']"
                :title="'是否确认删除记录'+scope.row.entityName+'?'" />
              <text-edit-button
                @click="handleUpdate(scope.row)" :perm="['rule:entity:info:update']" text="编辑"
                :roleType="['app']" />
              <text-button
                @click="copyHandler(scope.row)" icon="el-icon-copy-document" 
                :perm="['rule:entity:info:insert']" :roleType="['app']" text="复制" />
              <text-add-button
                @click="handleAdd(scope.row)" v-if="scope.row.parentId == '0'"
                :perm="['rule:entity:info:insert']" :roleType="['app']" text="新增属性" />
              <text-button
                @click="handleRefresh(scope.row)" v-if="scope.row.parentId == '0'" icon="el-icon-refresh"
                :perm="['rule:entity:info:insert', 'rule:entity:info:update']" :roleType="['app']" text="同步" />
            </template>
          </el-table-column>
        </el-table>
        <handle
          :editForm="editForm" ref="handleRef"
          :cateGroupCodeOptions="cateGroupCodeOptions"
          :isLeafOptions="isLeafOptions"
          :isObjectOptions="isObjectOptions"
          @get-list="getList" :entityClassOptions="entityClassOptions"
          @reset="reset" />
        <add-model-entity
          :modelEntityForm="modelEntityForm"
          @get-list="getList" :entityClassOptions="entityClassOptions"
          ref="modelRef" />
      </el-col>
    </el-row>
    <!-- 实体模型迁入对话框 -->
    <drag-dialog
      :title="upload.title"
      :close-on-click-modal="false"
      v-model="upload.open"
      width="400px"
      append-to-body
    >
      <el-select
        name="所属分组：" v-model="uploadParams.cateNamespace" placeholder="请选择所属分组" clearable
        style="width: 100%; margin-bottom: 20px;">
        <el-option
          v-for="dict in cateGroupCodeOptions" :key="dict.dictValue" :label="dict.dictLabel"
          :value="dict.dictValue" />
      </el-select>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".zip"
        :headers="upload.headers"
        :action="upload.url"
        :data="uploadParams"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <el-icon class="el-icon--upload"><upload-filled /></el-icon>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <template #tip>
          <div class="el-upload__tip">
            Tips：<br>
            1、迁入迁出主要用于多环境间数据传递，因此不建议用户对迁出的包进行修改。<br>
            2、迁入的实体模型如果已存在会被覆盖。
            <div class="el-upload__tip" style="color: red">
              提示：仅允许上传“zip”格式文件！
            </div>
          </div>
        </template>
      </el-upload>
      <template #footer>
        <dialog-footer @ok="submitFileForm" @cancel="cancelUpload" />
      </template>
    </drag-dialog>
    <!-- 新增或修改对话框 -->
    <el-dialog
      v-el-drag-dialog :title="dataSourceForm.title" :close-on-click-modal="false" v-model="dataSourceForm.open"
      width="50%" append-to-body>
      <el-form ref="dataSourceFormRef" :model="dataSourceForm.data" :rules="dataSourceForm.rules" label-width="120px">
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="数据源" prop="datasourceCode">
              <el-select v-model="dataSourceForm.data.datasourceCode" placeholder="请选择数据源" @change="getModelColumn" :disabled="dataSourceForm.isModify">
                <el-option
                  v-for="(op, index) in dataSourceOptions" :key="index" :label="op.datasourceCode"
                  :value="op.datasourceCode" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item
              label="数据源实体" prop="tableName"
              v-if="dataSourceForm.data.datasourceCode" required>
              <el-select-v2 v-model="dataSourceForm.data.tableName" multiple placeholder="请选择数据源实体" :disabled="dataSourceForm.isModify" :options="formEntityList" :props="{label: 'dictValue', value: 'dictValue'}" filterable>
              </el-select-v2>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <dialog-footer @ok="submitDataSourceForm" @cancel="cancelDataSource" />
      </template>
    </el-dialog>
    <!-- 同步对话框 -->
    <el-dialog
      v-el-drag-dialog :title="refreshEntityQuery.title" :close-on-click-modal="false" v-model="refreshEntityQuery.open"
      width="50%" append-to-body>
      <el-form ref="refreshEntityQueryRef" :model="refreshEntityQuery.data" label-width="120px">
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="数据源" prop="datasourceCode">
              <el-select v-model="refreshEntityQuery.data.datasourceCode" placeholder="请选择数据源" @change="getModelColumnFromRefresh">
                <el-option
                  v-for="(op, index) in dataSourceOptions" :key="index" :label="op.datasourceCode"
                  :value="op.datasourceCode" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="数据源实体" prop="tableName" v-if="refreshEntityQuery.data.datasourceCode">
              <el-select-v2 v-model="refreshEntityQuery.data.tableName" placeholder="请选择数据源实体" :options="formEntityList" :props="{label: 'dictValue', value: 'dictValue'}" filterable>
              </el-select-v2>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <dialog-footer @ok="submitRefreshEntityDialog" @cancel="cancelRefreshEntityDialog" />
      </template>
    </el-dialog>
  </div>
</template>

<script>
import {search, deleteByIds, selectById, entityTreeList, importFromDataSource, getTableList, refreshEntityInfo} from "@/platform/uni/api/uni/domain/index.ts";
// import { search, insert, deleteByIds, updateById, selectById } from "@rule/api/rule/entity/info";
import {debounceWrapper} from "@/utils/zmids.ts";
import handle from './handle.vue';
import addModelEntity from "./addModelEntity.vue";
// import { categoryTreeList } from '@rule/api/rule/config/category'
import {deepClone} from "@/utils/index.ts";
import { getToken } from '@/utils/auth';
import { getDatasource } from "@uni/api/uni/mda/table/info"
import defaultSettings from '@/settings'

function createEditForm() {
  return {
    // 控制 dialog
    open: false,
    // 弹出层标题
    title: '',
    // 是否修改操作
    isModify: false,
    // 表单参数
    data: {
      parentId: '',
      entityName: '',
      entityClass: '',
      entityDesc: '',
      isObject: '',
      remark: '',
      parentEntityDesc: '',
      parentEntityName: '',
      parentEntityId: ''
    },
    // 规则
    rules: {
      // 所属实体ID
      // parentId: [
      //   {required: true, message: '所属实体ID不可以为空', trigger: 'blur'}
      //   , {min: 1, max: 32, message: "所属实体ID的长度最多 32 个字符", trigger: "blur"}
      // ],
      // 实体名称
      entityName: [
        {required: true, message: '参数名称不可以为空', trigger: 'blur'}
        , {min: 1, max: 256, message: "参数名称的长度最多 256 个字符", trigger: "blur"}
        //校验类名规范
        , {pattern: /^[a-zA-Z][a-zA-Z0-9_]*$/, message: '只能输入英文、数字、_', trigger: 'blur'}
      ],
      // 参数类型
      entityClass: [
        {required: true, message: '参数类型不可以为空', trigger: 'change'}
      ],
      // 是否对象类型
      // isObject: [
      //   {required: true, message: '是否对象类型不可以为空', trigger: 'blur'}
      //   , {min: 1, max: 1, message: "是否对象类型的长度最多 1 个字符", trigger: "blur"}
      // ],
    },
  }
}

export default {
  name: "UniDomain",
  components: {handle, addModelEntity},
  data() {
    return {
      // 数据源选择列表
      dataSourceOptions: [],
      // 实体列表
      formEntityList: [],
      dataSourceForm: {
        // 控制 dialog
        open: false,
        // 弹出层标题
        title: '',
        // 是否修改操作
        isModify: false,
        // 表单参数
        data: {},
        // 规则
        rules: {
          // 数据源
          datasourceCode: [
            { required: true, message: '数据源不可以为空', trigger: 'blur' }
            , { min: 1, max: 64, message: "数据源的长度最多 64 个字符", trigger: "blur" }
          ],
          // 表名
          tableName: [
            { required: true, message: '表名不可以为空', trigger: 'blur' }
          ],
        },
      },
      // 同步对话框参数
      refreshEntityQuery: {
        title: "同步实体模型",
        open: false,
        data: {
          datasourceCode: '',
          tableName: '',
          entityId: ''
        }
      },
      entityClassOptions: [],
      cateNamespace: '',
      // cateNamespace: 'ZHDD_BUSINESS_RULE_TYPE',
      selectOption: undefined,
      defaultProps: {
        children: 'childList',
        label: 'entityName'
      },
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格树数据
      dataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 集成系统迁入参数
      upload: {
        // 是否显示弹出层
        open: false,
        // 弹出层标题
        title: '',
        cateNamespace: '',
        // 是否禁用上传
        isUploading: false,
        // 设置上传的请求头部
        headers: { [defaultSettings.tokenName]: 'Bearer ' + getToken() },
        // 上传的地址
        url: import.meta.env.VITE_APP_BASE_API + '/uni/entity/info/importZip'
      },
      // 上传参数
      uploadParams:{
        cateNamespace: '',
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        // cateNamespaceLike: 'ZHDD_BUSINESS_RULE_TYPE',
        cateNamespaceLike: '',
        // 实体名称
        entityNameLike: '',
        // 实体描述
        entityDescLike: '',
        //排序
        orderBy: 'UPDATE_TIME',
        sortDirect: 'DESC'
      },
      editForm: createEditForm(),
      // 是否对象类型的固定字典选项列表
      isObjectOptions: [{"dictValue": "Y", "dictLabel": "对象类型"}, {"dictValue": "N", "dictLabel": "原子类型"}],
      // 是否叶子节点的固定字典选项列表
      isLeafOptions: [{"dictValue": "Y", "dictLabel": "是"}, {"dictValue": "N", "dictLabel": "否"}],
      // 所属分组的数据字典选项列表：CATE_GROUP
      cateGroupCodeOptions: [],
      // 是否删除的固定字典选项列表
      isDeleteOptions: [{"dictValue": "Y", "dictLabel": "是"}, {"dictValue": "N", "dictLabel": "否"}],
      modelEntityForm: {
        // 控制 dialog
        open: false,
        // 弹出层标题
        title: '',
        data: {
          entityName: '',
          entityClass: 'object',
          entityDesc: '',
          attrList: [],
          cateNamespace: '',
          parentXpath: '',
        },

        // 规则
        rules: {
          // 参数名称
          entityName: [
            {required: true, message: '参数名称不可以为空', trigger: 'blur'}
            , {min: 1, max: 256, message: "参数名称的长度最多 256 个字符", trigger: "blur"}
            //校验类名规范
            , {pattern: /^[a-zA-Z][a-zA-Z0-9_]*$/, message: '只能输入英文、数字、_', trigger: 'blur'}
          ],
          // 参数类型
          entityClass: [
            {required: true, message: '参数类型不可以为空', trigger: 'change'}
          ],
        },
      },
      selectionIds: [], // 选中的id集合
    };
  },
  computed:{
    deleteBtnDisabled(){
      return this.selectionIds.length == 0
    }
 },
  created() {
    //初始化查询
    this.getList();
    // 获取数据字典：uni_cate_namespace
    this.getDicts("uni_cate_namespace").then(response => {
      this.cateGroupCodeOptions = response.data;
      this.cateNamespace = response.data[0].dictValue
    });
    // 获取数据字典：uni_data_type
    this.getDicts("uni_data_type").then(response => {
      response.data.map((e) => {
        e.dictLabel = `${e.dictLabel} (${e.dictValue})`
      })
      this.entityClassOptions = response.data;
    });
  },
  methods: {

   // 确定按钮
    submitDataSourceForm: debounceWrapper(function () {
      // this.modelEntity.data.isObject = 'Y';
      this.$refs['dataSourceFormRef'].validate((valid) => {
        if (valid) {
          const params = {
            datasourceCode: this.dataSourceForm.data.datasourceCode,
            tableNames: this.dataSourceForm.data.tableName.join(','),
            cateNamespace: this.queryParams.cateNamespaceLike
          }
          importFromDataSource(params).then(response => {
            this.msgSuccess("批量新增模型实体成功");
            this.getList();
          })
          this.cancelDataSource()
        }
      })
    }),

    /**
     * 根据所属分组改变列表信息
     */
    handleSelectCateGroup: debounceWrapper(function (val) {
      this.cateNamespace = val;
      this.selectOption = undefined
      console.log('val',val)
      this.queryParams.cateNamespaceLike = val
      //初始化查询
      this.getList();
    }),

    loadTree(tree, treeNode, resolve) {
      this.getList(tree.entityId, (data) => {
        data.map((e) => {
          e.parentData = tree;
        })
        resolve(data)
      });
    },
    /** 查询实体模型管理列表 */
    // 查询列表
    getList: debounceWrapper(function (parentId, callback) {
      this.loading = false;
      this.queryParams.cateNamespace = this.queryParams.cateNamespaceLike;
      if (!parentId) {
        this.dataList = [];
      }
      // return
      entityTreeList({...this.queryParams, parentId}).then(
          response => {
            if (response.data) {
              let data = deepClone(response.data);
              data.map((e) => {
                // e.hasChildren = (e.isObject === 'Y');
                e.children = e.childList
              })
              if (!parentId) {
                this.dataList = data;
              } else {
                callback(response.data);
              }
              this.loading = false;
            }
            console.log("this.dataList",this.dataList)
          }
      );
    }),
    /** 搜索按钮操作 */
    handleQuery() {
      // this.queryParams.parentId = row?.entityId;
      this.getList();
      // row = entityTreeData;
      // this.getEntityList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      // row = undefined;
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 表单重置
    reset() {
      // this.editForm = this.$options.data().editForm;
      // this.editForm = createEditForm()
      console.log(createEditForm())
      this.$nextTick(() => {
        this.$refs.handleRef.resetCurrentForm();
        this.$refs.modelRef.resetCurrentForm();
      })
    },
    // 新增模型实体按钮操作
    handleAddModel() {
      //所属分组
      // this.modelEntityForm = this.$options.data().modelEntityForm;
      this.$nextTick(() => {
        this.$refs.modelRef.resetCurrentForm();
        this.modelEntityForm.data.cateNamespace = this.queryParams.cateNamespaceLike;
        this.modelEntityForm.title = "新增模型实体";
        this.modelEntityForm.open = true;
      })

    },

    // 批量新增模型实体按钮操作
    handleBatchAddModel() {
      this.$nextTick(() => {
        this.resetDataSourceForm();
        this.dataSourceForm.data.cateNamespace = this.queryParams.cateNamespaceLike;
        this.dataSourceForm.open = true;
        this.dataSourceForm.title = "选择数据表";
        // 获取数据源选择列表
        this.getDataSourceOptions();
      })

    },

    resetDataSourceForm(){
      this.dataSourceForm.data = {
        // 主键ID
        tableId: undefined,
        // 数据源编码
        datasourceCode: undefined,
        // 表名
        tableName: '',
      };
      // 重置字段校验
      this.$refs.dataSourceFormRef && this.$refs.dataSourceFormRef.clearValidate();
      this.resetForm("dataSourceFormRef");
    },

     //数据源选择 选择建模-现有模板 - 下拉框
    getDataSourceOptions() {
      getDatasource().then(response => {
        console.log('response.data', response.data)
        this.dataSourceOptions = response.data
      })
    },
    // 获取实体
    getModelColumn(){
      if (this.dataSourceForm.data.datasourceCode != undefined) {
        const params = {
          datasourceCode: this.dataSourceForm.data.datasourceCode
        }
        getTableList(params).then((response) => {
          this.formEntityList = response.data
        })
      }
    },
    // 获取实体刷新用
    getModelColumnFromRefresh(){
      if (this.refreshEntityQuery.data.datasourceCode) {
        const params = {
          datasourceCode: this.refreshEntityQuery.data.datasourceCode
        }
        getTableList(params).then((response) => {
          this.formEntityList = response.data
        })
      }
    },

    // 迁出
    handleExport: debounceWrapper(function (row) {
      // 获取命名空间对应名称
      this.downloadUrl('/uni/entity/info/exportZip/' + row.entityId, undefined);
    }),

    // 迁入
    handleImport: debounceWrapper(function () {
      this.upload.title = '实体模型迁入'
      this.upload.open = true
    }),
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true
    },
    // 文件上传成功处理
    handleFileSuccess: debounceWrapper(function (response, file, fileList) {
      this.upload.open = false
      this.upload.isUploading = false
      this.$refs.upload.clearFiles()
      this.uploadParams.cateNamespace = '';
      this.$alert(response.msg, '迁入结果', { dangerouslyUseHTMLString: true })
      this.getList()
    }),
    // 提交上传文件
    submitFileForm() {
      if(!this.uploadParams.cateNamespace){
        this.$message.error("所属分组不能为空");
        return;
      };
      this.$refs.upload.submit();
    },
    // 取消上传
    cancelUpload() {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.uploadParams.cateNamespace = '';
    },
    cancelDataSource() {
      this.dataSourceForm.open = false
    },
    // 新增属性按钮操作
    handleAdd(row) {
      this.reset();
      this.editForm.isModify = false;
      this.editForm.title = "新增属性";
      this.editForm.data = {}
      this.$nextTick(() => {
        if (row) {
          // 父节点编码、名称：赋值
          this.editForm.data.parentEntityDesc = row?.entityDesc;
          this.editForm.data.parentEntityName = row?.entityName;
          this.editForm.data.parentId = row?.entityId;
          this.editForm.data.hasChildren = row?.hasChildren;
          this.editForm.data.parentXpath = row?.entityXpath
          //所属分组
          this.editForm.data.cateNamespace = this.queryParams.cateNamespaceLike;
          this.editForm.open = true;
        }
      })
    },
    // 同步实体模型属性列表
    handleRefresh(row) {
      // 获取数据源选择列表
      this.getDataSourceOptions();
      this.refreshEntityQuery.data.entityId = row.entityId;
      this.refreshEntityQuery.open = true;
    },
    submitRefreshEntityDialog: debounceWrapper(function () {
      refreshEntityInfo(this.refreshEntityQuery.data).then(res => {
        this.$message.success("同步成功！")
        this.cancelRefreshEntityDialog()
        this.getList()
      })
    }),
    cancelRefreshEntityDialog: debounceWrapper(function () {
      this.refreshEntityQuery.open = false
      this.refreshEntityQuery.data = {
        datasourceCode: '',
        tableName: '',
        entityId: ''
      }
    }),
    // 修改按钮操作
    handleUpdate: debounceWrapper(function (row) {
      this.reset();
      selectById(row.entityId).then(response => {
        this.editForm.data = response.data || {};
        // 父节点编码、名称：赋值
        this.editForm.data.parentEntityDesc =row.parentData ? row.parentData?.entityDesc : row?.entityDesc;
        this.editForm.data.parentEntityName = row.parentData ? row.parentData?.entityName :row?.entityName;
        this.editForm.data.hasChildren = row?.hasChildren;
        this.editForm.isModify = true;
        this.editForm.title = "修改参数信息";
        this.editForm.open = true;
      });
    }),
    copyHandler: debounceWrapper(function (row) {
      this.reset();
      selectById(row.entityId).then(response => {
        if (response.data) {
          this.editForm.data = response.data || {};
          // 父节点编码、名称：赋值
          this.editForm.data.parentEntityDesc =row.parentData ? row.parentData?.entityDesc : row?.entityDesc;
          this.editForm.data.parentEntityName = row.parentData ? row.parentData?.entityName :row?.entityName;
          this.editForm.data.entityName = `${this.editForm.data.entityName}_copy`;
          this.editForm.data.entityDesc = `${this.editForm.data.entityDesc}_副本`;
          this.editForm.data.hasChildren = row?.hasChildren;
          this.editForm.isModify = false;
          this.editForm.isCopy = true;
          this.editForm.title = "复制参数信息";
          this.editForm.open = true;
        }
      });
    }),
    // 删除按钮操作
    handleDelete: debounceWrapper(function (row) {
      deleteByIds(row.entityId)
          .then(() => {
            this.queryParams.entityCode = row?.entityCode;
            this.getList();
            // this.getEntityList();
            this.msgSuccess("删除成功");
            //刷新树
            // this.$refs.tree.getTreeData();
            this.getEntityTreeList();
            // entityTreeData
          }).catch(function () {
      });
    }),
    handleDeleteModelByIds(){
      const ids = this.selectionIds.join(',')
      deleteByIds(ids).then(()=>{
        this.getList();
        this.msgSuccess("删除成功");
      })
    },
    handleSelectionChange(selection){
      this.selectionIds = selection.map(item => item.entityId)
    },
  },
}
</script>
<style lang="scss">
.header-tree {
  .el-scrollbar__wrap {
    height: 100%;
    overflow: hidden auto;
  }
}
</style>
<style scoped lang="scss">

.custom-tree-node {
  font-size: 14px;
  width: 90%;

  .custom-tree-node-children {
    width: 95%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}
</style>
